<?php
class stockMan extends Admin {

    private $tab = array( 'stockMan' => '库存管理', 'stockTrans' => '库存调拨');
    private $color = array('深红', '大红','橘红','橘黄 ',
                             '玫瑰红','橙色','深黄','淡黄','草绿',
                            '墨绿', '柠檬黄', '黄绿', '蓝绿', '浅绿',
                           '天蓝', '湖蓝', '黑色', '白色', '紫色',
                           '红灰', '黄灰', '蓝灰', '紫灰', '浅灰');
    private $size = array('080CM','085CM','090CM','095CM','100CM',"105CM","110CM",
                            "115CM","120CM","125CM","130CM","135CM","140CM","145CM","150CM","155CM","160CM");

    public function __construct() {
        parent::__construct();
        $this->pk = "inOutStockNo";
    }

    public function index( $c, $a ) {
        $type = G( 'type', 'stockMan' );
        $method = "{$a}_{$type}";
        $this->$method( $c, $a, $type );
    }

    private function index_stockMan( $c, $a, $type ) {
        $type = G( 'type', 'stockMan' );
        $this->table = 'stockInfo';


        $conditions = array( 'goodsNumber' => '0');
        $this->pk = "id";

        $result = $this->Paged( G( 'page' ), $this->page_size )->findAll($conditions);

        $pager = $result['page'];
        $result = $result['result'];

        foreach($result as $key =>$val)
        {
            $result[$key]['color'] = $this->color[$val['color']];
            $result[$key]['size'] = $this->size[$val['size']];
        }

        include $this->display( $c );
    }

    private function index_stockTrans( $c, $a, $type ) {
        include $this->display( $c );
    }



    public function edit( $c, $a ) {

        if ( !$id = intval( G( 'id' ) ) ) {
            $this->error();
            exit;
        }

        $this->table = 'stockInfo'; // 数据库表名
        $result = $this->find(array( 'id' => $id ),'id'); // 查找数据


        $result['color'] = $this->color[$result['color'] ];
        $result['size'] = $this->size[ $result['size']];

        include $this->display( $c ); // 加载模板
    }


    public function search_stockMan( $c, $a ) {
        $this->table = 'stockInfo'; // 数据库表名
        $type = G( 'type', 'inStock' );

        $where = array( G( 'k' ) => G( 'v' ) );
        if ( $key = G( 'key' ) ) {
            $tmp = '';
            foreach ( $where as $k => $v ) {
                $tmp .= "{$k}='" . urldecode( $v ) . "' and ";
            }
            $where = $tmp ? ( $tmp . "goodsNo ={$key} " ) : '';
        }

        $this->pk = 'id';
        $result = $this->Paged()->findAll( $where );
        $pager = $result[ 'page' ];
        $result = $result[ 'result' ];

        foreach($result as $key =>$val)
        {
            $result[$key]['color'] = $this->color[$val['color']];
            $result[$key]['size'] = $this->size[$val['size']];
        }
        $res['key'] = G( 'key' );



        include $this->display( $c ); // 加载模板


    }

    public function saveStockInfo( $c, $a ) {

        if ( !$id = intval( G( 'id' ) ) ) {
            $this->error();
            exit;
        }

        $this->table = 'stockInfo'; // 数据库表名



        $rows['goodsNumber'] = $_POST['goodsNumber'];
        $this->update(array('id'=>$id), $rows);



    }










}








